package com.danbay.cloud.account.service.api;

import com.danbay.cloud.account.dto.*;
import com.danbay.framework.exception.BusinessException;
import com.danbay.framework.springnc.annotation.AutoController;
import com.danbay.framework.springnc.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 权限操作服务接口
 *
 * @author SJG
 *         2018/1/9.
 */
@AutoController
@RequestMapping("/account-service/permission")
@Api("权限操作服务接口")
public interface IPermissionService {


    /**
     * 添加权限定义
     *
     * @param permission 权限定义
     * @throws BusinessException 业务异常
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加权限定义")
    void add( @RequestBody PermissionDto permission) throws BusinessException;

    /**
     * 取所有权限
     * @return 权限列表
     */
    @RequestMapping(value = "/allPermissions", method = RequestMethod.GET)
    @ApiOperation(value = "取所有权限")
    List<PermissionInfoDto> allPermissions();

    /**
     * 添加权限组
     *
     * @param groupDto 组信息
     * @throws BusinessException 业务异常
     */
    @RequestMapping(value = "/addGroup", method = RequestMethod.POST)
    @ApiOperation(value = "添加权限组", notes = "根节点父级ID填0")
    void addGroup( @RequestBody PermissionGroupDto groupDto) throws BusinessException;

    /**
     * 修改权限组
     *
     * @param gid      权限组id
     * @param groupDto 权限组信息
     * @throws BusinessException 业务异常
     */
    @RequestMapping(value = "/editGroup", method = RequestMethod.POST)
    @ApiOperation(value = "修改权限组")
    void editGroup(@ApiParam("权限组id") @RequestParam("gid") Integer gid,  @RequestBody PermissionGroupDto groupDto) throws BusinessException;

    /**
     * 取指定parentId下的权限组列表
     *
     * @param parentId 父级组Id
     * @return 权限组列表
     */
    @RequestMapping(value = "/getGroups", method = RequestMethod.POST)
    @ApiOperation(value = "取权限组列表", notes = "不指定parentId时取所有权限组列表")
    List<PermissionGroupInfoDto> getGroups(@ApiParam("父级组Id") Integer parentId);

    /**
     * 取所有权限组列表(不包括权限组分组)
     *
     * @return 权限组列表
     */
    @RequestMapping(value = "/getPermissionGroups", method = RequestMethod.GET)
    @ApiOperation(value = "取所有权限组列表", notes = "组包括（权限分组和权限组分组）不包括权限组分组")
    List<PermissionGroupInfoDto> allPermissionGroups();

    /**
     * 为账户分配权限
     * 指定该账户有哪些权限组，需要排除权限组中哪些权限
     *
     * @param permission 账户权限
     * @throws BusinessException 业务异常
     */
    @RequestMapping(value = "/assignAccountPermission", method = RequestMethod.POST)
    @ApiOperation(value = "为账户分配权限", notes = "指定该账户有哪些权限组，需要排除权限组中哪些权限")
    void assignAccountPermission(@RequestBody AccountPermissionDto permission) throws BusinessException;

    /**
     * 取账户和账户组拥有的权限组列表
     *
     * @param userName 账号
     * @param groupId  账户组
     * @return 权限组列表
     * @throws BusinessException 业务异常
     */
    @RequestMapping(value = "/getAccountPermissions", method = RequestMethod.GET)
    @ApiOperation(value = "取账户和账户组拥有的权限组列表")
    List<PermissionGroupInfoDto> getAccountPermissions(@ApiParam("账号") String userName, @ApiParam("账户组") Integer groupId) throws BusinessException;


}
